/*******************************************************************************
 * Copyright (c) 2011 TXT e-solutions SpA
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * This work was performed within the IoT_at_Work Project
 * and partially funded by the European Commission's
 * 7th Framework Programme under the research area ICT-2009.1.3
 * Internet of Things and enterprise environments.
 *
 *
 * Authors:
 *     Cristoforo Seccia (TXT e-solutions SpA)
 *
 * Contributors:
 *      Domenico Rotondi (TXT e-solutions SpA)
 *******************************************************************************/
package it.txt.access.capability.demo.client.tcp;

import it.txt.access.capability.demo.client.view.model.ServerResponseInfoModel;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 *
 * @author Cristoforo Seccia (TXT e-solutions SpA)
 */
public class RequestClientSupport {

    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    private static ServerResponseInfoModel responseInfoModel = new ServerResponseInfoModel();
    
    public static final String EVENT_NAME_SERVICE_REQUEST_READY = "SERVICE_REQUEST_READY";

    public static final String EVENT_NAME_TCP_CONNECTION = "TCP_CONNECTION";

    public static final String EVENT_NAME_SERVICE_REQUEST_SENT = "SERVICE_REQUEST";

    public static final String EVENT_NAME_SERVICE_RESPONSE_RECEIVED = "SERVICE_RESPONSE";

    public static final String EVENT_NAME_SERVICE_RESPONSE_INFO = "SERVICE_RESPONSE_INFO";

    public static final String EVENT_NAME_SERVICE_REQUEST_FINISHED = "SERVICE_REQUEST_FINISH";
  
    public static final int STATE_UNKNOW = -1;

    public static final int STATE_SETTINGS = 0;

    public static final int STATE_ERROR = 2;

    public static final int STATE_OK = 1;

    //Listeneres methods
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }

    //Change states methods
    public void fireCapabilityServiceEvent(String propertyName, int oldState, int newState) {
        propertyChangeSupport.firePropertyChange(propertyName, oldState, newState);
    }

    protected void fireCapabilityResponseInfo(ServerResponseInfoModel serverResponse){
        propertyChangeSupport.firePropertyChange(EVENT_NAME_SERVICE_RESPONSE_INFO, responseInfoModel, serverResponse);
        responseInfoModel = serverResponse;
    }
}
